home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 10 / Amoszine 10 (Disk 1 of 3).adf / AMOSZINE / ARTS / DK_GibsonProb2.ASC / DK_GibsonProb2.ASC
Encoding:
Text File  |  1998-05-31  |  4.8 KB  |  120 lines

  1.                    @2YET ANOTHER PROBLEM FROM MR GIBSON!
  2.                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. @3
  4.                       FROM: Dave Kirk (Apex Systems)
  5.       @4
  6.       
  7.       Andy  is  now  coding  a  search  option for Disk Mag Creator.  His
  8.       problem is how to do a case insensitive search through a text file.
  9.       
  10.       There's two possibilities here.
  11.       @3
  12.       
  13.       Solution Number 1 - use of Arrays.
  14.       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@5
  15.  
  16.       When  writing Disk System, each line of a text file was stored in a
  17.       large  array (something like LINE$(2000) I seem to remember).  Each
  18.       one of these held a single line of text, so searching was easy.
  19.  
  20.       @1
  21.       All  I  did  was  something  like this (I haven't got the source in
  22.       front of me, this is from memory!) :-
  23.       
  24.  
  25. @1      Input "Enter string to search for:";USER$
  26.       LINES=2000
  27.       FOUND=0
  28.       TEMPA$=Upper$(USER$)
  29.       For C=1 to LINES
  30.          TEMPB$=Upper$(LINE$(C))
  31.          I=Instr(TEMPB$,TEMPA$)
  32.          If I<>0
  33.             Print "Pattern found at line";C
  34.             Add FOUND,1
  35.          End If
  36.       Next C
  37.       If FOUND=0
  38.          Print "Search pattern not found!"
  39.       Endif
  40. @4      
  41.       
  42.       That's  the  basic principle of using arrays to search.  Don't type
  43.       this  example  into the editor though, because it won't do anything
  44.       as  it is.  You would first need to set up an array containing your
  45.       text  document,  LINE$(2000)  for  example.   You may need to set a
  46.       larger variable buffer (Set Buffer xx) to do this.
  47.       
  48.       
  49.   @3    Solution Number 2 - Converting the entire document to upper case.
  50.       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51.       @4This  solution  is  only a theory, as I haven't had time to test or
  52.       write  a routine to do it yet.  Basically, you will need two memory
  53.       banks.   The  first  one holds your document in it's original form,
  54.       and  the  second  one is a kind of temporary buffer which holds the
  55.       entire document but in UPPER CASE.
  56.       @1
  57.       Here's the theory:-
  58.       @5
  59.       1. Load your text file into, say, bank 10, using the Bload command.
  60.       2. Create a temporary bank like this:-
  61.       
  62.          Reserve as data 11,Length(10)
  63.       
  64.       3. Now  we  need  to convert it to upper case.  This program should
  65.          do the job just fine, although I haven't actually tried it:-
  66.       @1
  67.          For C=0 to Length(10)
  68.             T=Peek(Start(10)+C)
  69.             If T>96 And T<123           ;Lower case characters use 97-122
  70.                Poke Start(11)+C,T-32    ;Change to UPPER CASE equivalent
  71.             End If
  72.          Next
  73.       
  74.       @4
  75.       If  my theory is correct, you should now have an exact copy of your
  76.       document,  but  completely in UPPER CASE.  You will then be able to
  77.       convert  your  search  string to UPPER CASE, and simply do a memory
  78.       search (using "Hunt") that way.
  79.             @3
  80.       This method has no real disadvatages, but two points to note are:-
  81.       @5
  82.       1. You  will need enough space to store your text file twice over -
  83.          once  for  bank  10  (the  original  doc), and again for bank 11
  84.          (the document converted to UPPER CASE).
  85.       2. The  longer your text file is, the longer it takes to convert to
  86.          UPPER  CASE, although PEEKing and POKEing is very quick, so this
  87.          shouldn't cause too many problems.
  88.       
  89.       @1
  90.       SUMMARY
  91.       ~~~~~~~@4
  92.       The  basic  idea behind doing a case insensitive search is that you
  93.       have to do a comparison between the search string and the document.
  94.       Before  this,  you  need  to convert both the search string and the
  95.       document  to  UPPER  case. 
  96.  
  97.       @4This applies to whichever of the two methods shown above you choose
  98.       to  adapt,  whether  checking just one line of text at a time using
  99.       the  "Instr" command, as in example 1, or using the "Hunt" command
  100.       to look through an entire document as in example 2.
  101.       @5
  102.       Thanx  for  the  tips Dave.  I too came up with the same idea as in
  103.       Example  2  above and it works fine.  However, your code to convert
  104.       text to UPPERCASE isn't perfect!
  105.       
  106.       It's far easier to use LDos command @3(Lstr) @5like so:@1
  107.  
  108.       Reserve As Work 11,Length(10)
  109.       ALL$=Upper$(Lstr(Start(10),Length(10))) : Rem ** LDOS Required!
  110.       Poke$ Start(11),ALL$+Chr$(10) : Rem ** Amos Pro Required!
  111.       Bank Swap 10,11
  112.       @5
  113.       Please  also  note  that the @3Poke$ @5command is Amos Pro only and one
  114.       which I have used from day one of programming in Amos.  (In fact, I
  115.       needed this command, so upgraded to Amos Pro to use it!)
  116.  
  117.       I  think  CRAFT  has  a  POKE$  command  (or  similar) so you could
  118.       probably use that, all you Classic Amos Users.
  119.  
  120.       Andy Gibson.                                                   @1End.